name: Release

on:
  push:
    tags:
      - "v*.*.*"

jobs:
  release:
    name: Build and publish release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup python
        uses: actions/setup-python@v4
        with:
          python-version: "3.10"

      - name: Setup poetry
        uses: Gr1N/setup-poetry@v8

      - name: Build package
        run: poetry build

      - name: Source distribution artifact
        uses: actions/upload-artifact@v3
        with:
          name: sdist
          path: dist/quantpiler-*.tar.gz

      - name: Wheel distribution artifact
        uses: actions/upload-artifact@v3
        with:
          name: wheel
          path: dist/quantpiler-*-py3-none-any.whl

      - name: Login to PyPI
        run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}

      - name: Publish to PyPI
        run: poetry publish

      - name: Make a GitHub release
        uses: softprops/action-gh-release@v1
        with:
          files: dist/*
